home *** CD-ROM | disk | FTP | other *** search
- head 1.7;
- branch ;
- access ;
- symbols sprited:1.6.1;
- locks ; strict;
- comment @ * @;
-
-
- 1.7
- date 91.11.21.18.12.58; author jhh; state Exp;
- branches ;
- next 1.6;
-
- 1.6
- date 90.02.17.14.47.00; author douglis; state Exp;
- branches 1.6.1.1;
- next 1.5;
-
- 1.5
- date 90.02.15.17.21.47; author douglis; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 89.11.04.21.50.22; author douglis; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 89.09.11.17.25.55; author douglis; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.07.20.18.12.18; author ouster; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.06.10.16.23.50; author ouster; state Exp;
- branches ;
- next ;
-
- 1.6.1.1
- date 91.12.02.19.57.52; author kupfer; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.7
- log
- @if was backwards so on reopen our own buffer was used if the stream
- previously had its own, and similarly we used the existing buffer
- if it was our own. If the user did a setvbuf before freopen
- his buffer would be lost.
- @
- text
- @/*
- * freopen.c --
- *
- * Source code for the "freopen" library procedure.
- *
- * Copyright 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/freopen.c,v 1.6 90/02/17 14:47:00 douglis Exp $ SPRITE (Berkeley)";
- #endif not lint
-
- #include "stdio.h"
- #include "fileInt.h"
- #include "stdlib.h"
- #include <sys/file.h>
-
- /*
- *----------------------------------------------------------------------
- *
- * freopen --
- *
- * Close the file currently associated with a stream and then re-open
- * the stream on a new file.
- *
- * Results:
- * The return value is NULL if an error occurred in opening the
- * new file, or stream otherwise.
- *
- * Side effects:
- * A file is opened, and a stream is initialized. Errors in closing
- * the old stream are ignored.
- *
- *----------------------------------------------------------------------
- */
-
- FILE *
- freopen(fileName, access, stream)
- char *fileName; /* Name of file to be opened. */
- char *access; /* Indicates type of access, just as for
- * fopen. */
- FILE *stream; /* Name of old stream to re-use. */
- {
- int id, flags, read, write, oldFlags;
-
- if (stream->readProc != (void (*)()) StdioFileReadProc) {
- return (FILE *) NULL;
- }
-
- if (stream->flags != 0) {
- fflush(stream);
- id = (int) stream->clientData;
- close(id);
- }
-
- /*
- * Open a new stream and let it re-use the old stream's structure.
- */
-
- flags = StdioFileOpenMode(access);
- if (flags == -1) {
- return (FILE *) NULL;
- }
- id = open(fileName, flags, 0666);
- if (id < 0) {
- return (FILE *) NULL;
- }
- read = write = 0;
- if ((access[1] == '+') || ((access[1] == 'b') && (access[2] == '+'))) {
- read = write = 1;
- } else if (access[0] == 'r') {
- read = 1;
- } else {
- write = 1;
- }
- if (access[0] == 'a') {
- (void) lseek(id, 0L, L_XTND);
- }
- oldFlags = stream->flags & (STDIO_NOT_OUR_BUF | STDIO_LINEBUF);
- if (!(stream->flags & STDIO_NOT_OUR_BUF)) {
- Stdio_Setup(stream, read, write, stdioTempBuffer, 0,
- StdioFileReadProc, StdioFileWriteProc, StdioFileCloseProc,
- (ClientData) id);
- } else {
- Stdio_Setup(stream, read, write, stream->buffer, stream->bufSize,
- StdioFileReadProc, StdioFileWriteProc, StdioFileCloseProc,
- (ClientData) id);
- }
- stream->flags |= oldFlags;
- return stream;
- }
- @
-
-
- 1.6
- log
- @fixed typo w/ streamID v. id var name.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/freopen.c,v 1.5 90/02/15 17:21:47 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
- d87 1
- a87 1
- if (stream->flags & STDIO_NOT_OUR_BUF) {
- @
-
-
- 1.6.1.1
- log
- @Initial branch for Sprite server.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/freopen.c,v 1.6 90/02/17 14:47:00 douglis Exp $ SPRITE (Berkeley)";
- @
-
-
- 1.5
- log
- @make same check as fopen for seeking to end of file.
-
-
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/freopen.c,v 1.4 89/11/04 21:50:22 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
- d84 1
- a84 1
- (void) lseek(streamID, 0L, L_XTND);
- @
-
-
- 1.4
- log
- @fix in case already open
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/freopen.c,v 1.3 89/09/11 17:25:55 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
- d82 3
- @
-
-
- 1.3
- log
- @don't refuse to reopen just because the original stream wasn't valid
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/freopen.c,v 1.2 88/07/20 18:12:18 ouster Exp Locker: douglis $ SPRITE (Berkeley)";
- d51 1
- a51 1
- int id, flags, read, write;
- d83 1
- d93 1
- @
-
-
- 1.2
- log
- @Change file streams so that fdopen can be called more than once
- for a given stream id, and get separate buffers.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: freopen.c,v 1.1 88/06/10 16:23:50 ouster Exp $ SPRITE (Berkeley)";
- d53 1
- a53 2
- if ((stream->readProc != (void (*)()) StdioFileReadProc)
- || (stream->flags == 0)) {
- d57 5
- a61 3
- fflush(stream);
- id = (int) stream->clientData;
- close(id);
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: atoi.c,v 1.1 88/04/28 17:20:23 ouster Exp $ SPRITE (Berkeley)";
- d51 1
- a51 1
- int id, newId, flags;
- d63 1
- a63 2
- * Open a new stream. If it doesn't get opened in the same slot as
- * the old one, then move it so it is the same.
- d70 2
- a71 2
- newId = open(fileName, flags, 0666);
- if (newId < 0) {
- d74 7
- a80 5
- if (newId != id) {
- if (dup2(newId, id) == -1) {
- return (FILE *) NULL;
- }
- close(newId);
- d82 8
- a89 2
- if (access[0] == 'a') {
- (void) lseek(id, 0, L_XTND);
- a90 1
- fdopen(id, access);
- @
-